package com.test.springsecurity.service.impl;

import com.test.springsecurity.entity.AppUser;
import com.test.springsecurity.mapper.UserMapper;
import com.test.springsecurity.service.UserService;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Resource
    private PasswordEncoder passwordEncoder;

    @Transactional
    @Override
    public boolean add(AppUser appUser) {
        //加密密码
        appUser.setPassword(passwordEncoder.encode(appUser.getPassword()));

        //调用mapper插入数据

        return userMapper.add(appUser);
    }
}
